package com.fbinggun.fbinggunutil.statistics;

import com.fbinggun.fbinggunutil.*;
import com.fbinggun.fbinggunutil.API.PluginUtil;
import com.fbinggun.fbinggunutil.command.MainCommand;
import com.fbinggun.fbinggunutil.statistics.command.StatistCommand;
import com.fbinggun.fbinggunutil.statistics.datatype.DoubleInfo;
import com.fbinggun.fbinggunutil.statistics.datatype.IntInfo;
import com.fbinggun.fbinggunutil.statistics.datatype.LongInfo;
import com.fbinggun.fbinggunutil.statistics.datatype.StringInfo;
import com.fbinggun.sql.SQLite;

import java.sql.SQLException;

public class StatistMain extends FPluginModule {

    private JsonTable statisticsTable;
    private MainCommand statCommand;
    private StatisticsAPI statApi;
    private StatisticsProject project;

    public StatisticsProject getProject() {
        return project;
    }

    protected JsonTable getStatisticsTable() {
        return statisticsTable;
    }

    public StatisticsAPI getStatApi() {return statApi;}

    private MainCommand getStatCommand() {
        return statCommand;
    }

    @Override
    public void onEnable() {
       SQLite sql=getFBinggunUtil().getSql();
        FPlugin plugin=getFBinggunUtil().getPlugin();
        statApi=new StatisticsAPI();
        try {
            statisticsTable=new JsonTable(sql,"statisticsTable");
        } catch (SQLException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        statCommand= new StatistCommand(plugin,"Statistics");
        //注册信息类型
        StatisticsInfo.register(new DoubleInfo("id",0d));
        StatisticsInfo.register(new StringInfo("id",""));
        StatisticsInfo.register(new IntInfo("id",0));
        StatisticsInfo.register(new LongInfo("id",0l));
        project=new StatisticsProject();
        //注册PAPI变量
        if(PluginUtil.isPlaceholderAPI()){
            new StatistPapi(this).register();
        }
    }

    @Override
    public void onDisable() {

    }

    @Override
    public void onLoad() {

    }


}
